package com.xuecheng.teaching.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xuecheng.api.teaching.WorkRecApi;
import com.xuecheng.api.teaching.model.dto.CourseWorkRecDTO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.teaching.common.util.UAASecurityUtil;
import com.xuecheng.teaching.service.CourseWorkRecService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CourseWorkRecController implements WorkRecApi {

    @Autowired
    private CourseWorkRecService courseWorkRecService;

    /**
     * 分页查询作业
     *
     * @param
     * @return
     */
    @Override
    @PostMapping("work-record/list")
    public PageVO<CourseWorkRecDTO> queryWorkToPreview(PageRequestParams pageRequestParams, @RequestBody String courseName) {

        Long companyId = UAASecurityUtil.getCompanyId();

        JSONObject courseNameJsonString = JSON.parseObject(courseName);
        String name = (String) courseNameJsonString.get("courseName");
        return courseWorkRecService.queryWorkToPreview(pageRequestParams, name, companyId);
    }

}
